package com.madou.dbtool.redis.node;


import com.madou.common.annotation.HideClass;
import com.madou.dbtool.common.icon.AllIcons;
import com.madou.dbtool.event.DBEventManager;
import com.madou.dbtool.redis.event.OpenRedisDataEvent;
import com.madou.dbtool.redis.manager.RedisNodeInfo;
import com.madou.dbtool.redis.manager.RedisSourceManager;
import com.madou.dbtool.redis.utils.BytesToStringUtil;
import com.madou.dbtool.ui.tree.DataSourceNode;

import javax.swing.*;
import java.sql.SQLException;
import java.util.UUID;

/**
 * @author miukoo
 * Redis数据库key节点
 */
@HideClass
public class RedisKeysNode extends DataSourceNode {

    // 资源管理器
    RedisSourceManager redisSourceManager;
    // 当前数据库的索引
    String key;
    RedisNodeInfo redisNodeInfo;
    int index;

    public RedisKeysNode(DataSourceNode parent, RedisSourceManager redisSourceManager, String key, RedisNodeInfo redisNodeInfo, int index) {
        super(parent);
        this.redisSourceManager = redisSourceManager;
        this.key = BytesToStringUtil.byte2Hex(key.getBytes());
        this.index = index;
        this.redisNodeInfo = redisNodeInfo;
    }

    @Override
    public DataSourceNode getChildren(DataSourceNode parent, int index) {
        return null;
    }


    @Override
    public void doubleClick(JTree jTree) throws SQLException {
        DBEventManager.notice(new OpenRedisDataEvent(getId(),redisSourceManager,redisNodeInfo,key,index));
    }

    @Override
    public String getText() {
        return key;
    }

    @Override
    public Icon getIcon() {
        return AllIcons.Common.TEXT;
    }

    @Override
    public int countChild() {
        return 0;
    }

    @Override
    public boolean hasChild() {
        return false;
    }
}
